<template>
	<div class="system-dic-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入标记人" style="max-width: 180px" v-model="state.tableData.param.param.user_name.val"> </el-input>
				<el-input size="default" placeholder="请输入标记内容" style="max-width: 180px" v-model="state.tableData.param.param.content.val"> </el-input>
				<el-input size="default" placeholder="请输入渠道名" style="max-width: 180px" v-model="state.tableData.param.param.platform_name.val"> </el-input>
				<el-input size="default" placeholder="请输入调查id" style="max-width: 180px" v-model="state.tableData.param.param.offerid.val"> </el-input>
				<el-date-picker size="default" style="width: 280px;" v-model="state.tableData.param.param.create_time.val"
					type="daterange" range-separator="-" start-placeholder="开始时间" end-placeholder="结束时间"
					:default-time="[new Date(0, 0, 0, 0, 0, 0), new Date(0, 0, 0, 23, 59, 59)]" value-format='X' />
				<el-button size="default" type="primary"  @click="seachClick">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
			</div>
			<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column prop="user_id" label="标记人id" show-overflow-tooltip></el-table-column>
				<el-table-column prop="user_name" label="标记人" show-overflow-tooltip></el-table-column>
				<el-table-column prop="content" label="标记内容" show-overflow-tooltip></el-table-column>
				<el-table-column prop="platform_name" label="渠道名" show-overflow-tooltip></el-table-column>
				<el-table-column prop="offerid" label="调查id" show-overflow-tooltip></el-table-column>
				<el-table-column label="创建时间" show-overflow-tooltip>
					<template #default="scope">
						<span>{{ dateFormatYMDHMS(scope.row.create_time * 1000)}}</span>
                    </template>
				</el-table-column>
				<el-table-column label="操作" width="100" v-auth="'/platformoffer/del'">
					<template #default="scope">
						<el-button size="small" text type="primary"  @click="onRowDel(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				:current-page="state.tableData.param.page"
				background
				:page-size="state.tableData.param.limit"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</el-card>
	</div>
</template>

<script setup name="combo">
import { reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { platformofferApi } from '/@/api/platformoffer/index';
import commonFunction from '/@/utils/commonFunction';
// 定义变量内容
const { dateFormatYMDHMS } = commonFunction();
const paramOp = {
	user_name:'%%',
	platform_name:'%%',
	offerid:'%%',
	content:'%%',
	create_time: 'time',
}
const state = reactive({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			param:{
				user_name:{},
				platform_name:{},
				offerid:{},
				content:{},
				create_time:{}
			},
			page: 1,
			limit: 10,
		},
	},
});
// 初始化表格数据
const getTableData = () => {
	state.tableData.loading = true;
	for (let key in state.tableData.param.param) {
		if (state.tableData.param.param[key].val && state.tableData.param.param[key].val !== '') {
			state.tableData.param.param[key].op = paramOp[key] || '='
		}else{
			state.tableData.param.param[key] = {}
		}
	}
    platformofferApi().index(state.tableData.param).then(res=>{
        state.tableData.data = res.data.list;
        state.tableData.total = res.data.total;
        state.tableData.loading = false;
    })
};
// 删除
const onRowDel = (row) => {
	ElMessageBox.confirm(`此操作将永久删除，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(() => {
			platformofferApi().del({ids:row.id}).then(res=>{
                getTableData();
                ElMessage.success('删除成功');
            })
		})
		.catch(() => {});
};
const seachClick = () =>{
	onHandleCurrentChange(1)
}
// 分页改变
const onHandleSizeChange = (val) => {
	state.tableData.param.limit = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val) => {
	state.tableData.param.page = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>
